﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.WSIdentityFaultException
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Globalization;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;

namespace Microsoft.InfoCards
{
  internal class WSIdentityFaultException : InfoCardBaseException
  {
    private const int HRESULT = -1073413871;

    public static void ThrowIfFaultMessage(Message message, CultureInfo displayCulture)
    {
      if (message.IsFault)
      {
        MessageFault fault1 = MessageFault.CreateFault(message, 2000000);
        FaultException fault2 = FaultException.CreateFault(fault1);
        string message1 = fault2.Message;
        string extendedMessage = string.Empty;
        if (fault1.Reason != null)
        {
          FaultReasonText matchingTranslation = fault1.Reason.GetMatchingTranslation(displayCulture);
          if (matchingTranslation != null)
            extendedMessage = matchingTranslation.Text;
        }
        if (fault1.HasDetail)
        {
          using (XmlReader atDetailContents = (XmlReader) fault1.GetReaderAtDetailContents())
          {
            if (atDetailContents.Read())
              message1 = string.Format((IFormatProvider) CultureInfo.CurrentUICulture, SR.GetString("FaultMessageFormat"), (object) fault2.Message, (object) atDetailContents.ReadOuterXml());
          }
        }
        throw InfoCardTrace.ThrowHelperErrorWithNoLogging((Exception) new WSIdentityFaultException(message1, extendedMessage, (Exception) fault2));
      }
    }

    public WSIdentityFaultException()
      : base(-1073413871)
    {
    }

    public WSIdentityFaultException(string message)
      : base(-1073413871, message)
    {
    }

    public WSIdentityFaultException(string message, string extendedMessage, Exception inner)
      : base(-1073413871, message, extendedMessage)
    {
      if (!(inner is FaultException))
        return;
      this.MapFaultException(inner as FaultException);
    }

    protected WSIdentityFaultException(SerializationInfo si, StreamingContext sc)
      : base(-1073413871, si, sc)
    {
    }

    private void MapFaultException(FaultException fe)
    {
      if (fe == null || fe.Code == null || (fe.Code.SubCode == null || !(fe.Code.SubCode.Namespace == "http://schemas.xmlsoap.org/ws/2005/05/identity/fault")))
        return;
      switch (fe.Code.SubCode.Name)
      {
        case "InformationCardRefreshRequired":
          this.HResult = -1073413760;
          break;
        case "MissingAppliesTo":
          this.HResult = -1073413759;
          break;
        case "InvalidProofKey":
          this.HResult = -1073413758;
          break;
        case "UnknownInformationCardReference":
          this.HResult = -1073413757;
          break;
        case "FailedRequiredClaims":
          this.HResult = -1073413756;
          break;
      }
    }
  }
}
